<!doctype html>
<html>

	<head>
		<meta charset="utf-8">
		<meta name="viewport"
			content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0,viewport-fit=cover" />
		<meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
		<title>采购退货-编辑</title>
		<link rel="stylesheet" type="text/css" href="../../css/vant.css">
		<link rel="stylesheet" type="text/css" href="../../css/base.css" />
		<link rel="stylesheet" type="text/css" href="../../css/local.css" />
		<link rel="stylesheet" type="text/css" href="../../script/layer_new/css/layui.css" />
		<script type="text/javascript" src="../../script/layer_new/layui.js"></script>
		<script type="text/javascript" src="../../script/jquery.js"></script>
		<script type="text/javascript" src="../../script/vue.min.js"></script>
		<script type="text/javascript" src="../../script/vant.min.js"></script>
		<script type="text/javascript" src="../../script/fastclick.js"></script>
		<script type="text/javascript" src="../../script/base.js"></script>
		<script type="text/javascript" src="../../script/scanTransf.js"></script>
		<style type="text/css">
			.delCode-title,
			.delCode-content {
				width: 15%;
			}

			.ware-title,
			.ware-content {
				width: 35%;
			}

			.qty-title,
			.qty-content {
				width: 25%;
			}

			.pos-title,
			.pos-content {
				width: 25%;
			}
		</style>
	</head>

	<body>
		<div id="app" v-cloak>
			<div class="box">
				<van-nav-bar class="head" :title="titleName" :safe-area-inset-top="true" left-arrow
					@click-left="onClickLeft">
					<span slot="right" @click="openScan" v-if="!isPDA">
						<img src="../../image/scan.png" />
					</span>
				</van-nav-bar>

				<div class="content">
					<van-collapse v-model="activeNames">
						<van-collapse-item title="表单详情" name="1" title-class="mTitle" class="custom-collapse-item">
							<template #icon>
								<div class="mIcon">
									<van-icon name='edit' size="18px" color="#51d0d0"></van-icon>
								</div>
							</template>

							<van-row class="mainContent">
								<!-- <van-col span="24">
									<van-field label="出库仓库" v-model="form.FWarehouseName" readonly
										@click="openBaseScreen('仓库')" left-icon="wap-home-o" right-icon="arrow"
										required>
									</van-field>
								</van-col> -->
								<van-col span="24">
									<van-field label="供应商" v-model="form.FSupplyName" readonly
										@click="openBaseScreen('供应商')" left-icon="manager-o" right-icon="arrow"
										required>
									</van-field>
								</van-col>
								<van-col span="24">
									<van-field label="单据日期" v-model="form.FDate" left-icon="underway-o"
										right-icon="arrow" readonly @click="openDate(1)">
									</van-field>
								</van-col>
								<van-col span="24">
									<van-field v-if="!isPDA" label="采购订单号" v-model="form.BillNO" left-icon="bar-chart-o"
										readonly @click="rowOpenScan">
										<van-icon slot="right-icon" name="scan" size="22px" color="#51d0d0"></van-icon>
									</van-field>
									<van-field v-else label="采购订单号" v-model="form.BillNO" left-icon="bar-chart-o"
										readonly>
									</van-field>
								</van-col>
							</van-row>
						</van-collapse-item>
					</van-collapse>

					<div class="midPanel">
						<van-button size="small" block @click="openBaseScreen('产品')" :disabled="form.BillNO!=''">选择产品
						</van-button>
					</div>

					<div class="detail">
						<div class="detail-label">
							<div :class="tabIndex==1?'on':''" @click="tabIndex = 1;">箱码明细</div>
							<div :class="tabIndex==2?'on':''" @click="tabIndex = 2;">产品批次码明细</div>
							<div :class="tabIndex==3?'on':''" @click="tabIndex = 3;">采购订单明细</div>
						</div>

						<div v-show="tabIndex==1" class="detail-content">
							<div>
								<div class="button" v-if="!formDetail.length">
									<span>暂无出库明细</span>
								</div>
								<div class="rowBoxContainer">

								</div>
							</div>
						</div>

						<div v-show="tabIndex==2" class="detail-content">
							<div>
								<div class="button" v-if="!formDetail.length">
									<span>暂无产品批次码明细</span>
								</div>
								<div class="rowFBatchNoContainer">

								</div>
							</div>
						</div>

						<div v-show="tabIndex==3" style="padding: 0px 5px;">
							<div>
								<div class="button" v-if="!SiOrderDetail.length">
									<span>暂无采购订单明细</span>
								</div>
								<div class="table" v-if="SiOrderDetail.length">
									<div class="table-full">
										<table style="white-space:nowrap;text-align:center">
											<tbody>
												<tr>
													<th>序号</th>
													<th>产品信息</th>
													<th>计量单位</th>
													<th>订单完成数量</th>
													<th>剩余可退数量</th>
													<!-- <th>所在库位</th> -->
												</tr>
												<tr v-for="(item,index) in SiOrderDetail" :key="index">
													<td>{{index+1}}</td>
													<td>{{item.ProductName}}</td>
													<td>{{item.UnitName}}</td>
													<td>{{item.WCQty}}</td>
													<td>{{item.SYQty}}</td>
													<!-- <td>{{item.allStorage}}</td> -->
												</tr>
											</tbody>
										</table>
									</div>
								</div>
							</div>
						</div>
					</div>

				</div>

				<div class="bottom">
					<van-button v-if="!form.Approve" size="small" color="#51d0d0" :disabled="ifConfirm"
						:loading="ifConfirm" @click="confirmSub">保存</van-button>
					<van-button v-if="!form.Approve && form.FStockID" size="small" color="#a33d3b" :disabled="ifConfirm"
						:loading="ifConfirm" @click="ApproveSubmit">审核</van-button>
					<van-button v-if="form.Approve" size="small" color="#a33d3b" :disabled="ifConfirm"
						:loading="ifConfirm" @click="ApproveSubmit">取消审核</van-button>
				</div>
			</div>

			<van-popup v-model="showDate" position="bottom">
				<van-datetime-picker v-model="currentDate" type="date" @confirm="confirmDate" @cancel="cancelDate"
					cancel-button-text="清空" />
			</van-popup>

		</div>
	</body>
	<script src="../../script/uni.webview.1.5.4.js"></script>
	<script type="text/javascript">
		// 开启 h5 页面 与 vue主页面的 信息交互
		document.addEventListener('UniAppJSBridgeReady', function() {

		})

		var userInfo = APP.getUserInfo();
		var seqNo = 0,
			currScanRow = -1;
		var new_seqNo = 0,
			new_currScanRow = -1;
		var selectFid = '',
			selectFname = '';
		var new_selectFid = '',
			new_selectFname = '';

		// 扫码结果处理
		function scanHandler(scanData) {
			if (vm.scanDisabled) {
				layer.open({
					content: '数据提交中,请稍后再试',
					skin: 'msg',
					time: 2000
				});
				return false;
			}
			if (!scanData) {
				layer.open({
					content: '请扫描正确的条码',
					skin: 'msg',
					time: 2000
				});
				return false;
			}

			if (scanData.type == '采购订单') {
				if (currScanRow > -1 && !vm.form.BillNO) {
					layer.open({
						content: '已存在非采购订单产品,无法加载采购订单产品!',
						skin: 'msg',
						time: 2000
					});
					return false;
				}

				if (!vm.form.FDate) {
					layer.open({
						content: '请选择日期',
						skin: 'msg',
						time: 2000
					});
					return false;
				}

				vm.scanDisabled = true;
				var obj = {
					SiOrderID: scanData.data.code
				}
				APP.jqueryAjax('SM_CGTH_CGDD', obj, function(res) {
					console.log(JSON.stringify(res.ds))

					if (res.ds[0].status == 500) {
						vm.scanDisabled = false;
						layer.open({
							content: res.ds[0].msg,
							skin: 'msg',
							time: 2000
						});
					} else {
						vm.scanDisabled = false;
						if (res.ds.length) {
							if (vm.form.BillNO != res.ds[0].BillNO) {
								$(".rowBoxContainer").children().remove(); //清空产品列表下的所有产品箱码列表
							}
							vm.form.BillNO = res.ds[0].BillNO; //退货单
							vm.form.FSupplyID = res.ds[0].FSupplyID;
							vm.form.FSupplyName = res.ds[0].SupplyName;
							vm.form.SiOrderID = res.ds[0].SiOrderID;
							vm.SiOrderDetail = [];
							for (var i in res.ds) {
								res.ds[i].totalBoxNum = 0;
								res.ds[i].totalQty = 0;
								vm.insertProductRow(res.ds[i]);
							}

						} else {
							vm.form.BillNO = '';
						}
					}

				})
			} else if (scanData.type == '库位') {
				vm.scanDisabled = true;
				let obj = {
					FStorageCode: scanData.data.code,
					ProductID: $('.rowFBatchNoContainer #ProductID' + new_currScanRow).text(),
					FBatchNo: $('.rowFBatchNoContainer #FBatchNo' + new_currScanRow).text(),
				}
				console.log(JSON.stringify(obj));
				APP.jqueryAjax('Get_Storage_CPPCM', obj, function(res) {
					vm.scanDisabled = false;
					if (res.ds[0] && res.ds[0].status == 500) {
						layer.open({
							content: res.ds[0].msg,
							skin: 'msg',
							time: 2000
						});

					} else {
						if (res.ds.length > 0) {
							for (let i = 0; i < res.ds.length; i++) {
								let rowObj = {
									ProductID: res.ds[i].ProductID,
									ProductName: res.ds[i].ProductName,
									FBatchNo: res.ds[i].FBatchNo,
									FWarehouseName: res.ds[i].FWarehouseName,
									FWarehouseID: res.ds[i].FWarehouseID,
									fid: res.ds[i].FStorageID,
									fname: res.ds[i].FStorageCode,
									qty: res.ds[i].FQty
								}
								vm.insertFBatchNoQrCode(rowObj, new_currScanRow);
							}

						} else {
							layer.open({
								content: '当前扫描的库位没有对应产品批次的可出库库存！！！',
								skin: 'msg',
								time: 2000
							});
						}

					}

				})
			} else if (scanData.type == '箱码') {
				if (vm.form.Approve) {
					layer.open({
						content: '该单据已审核!不能扫箱码!',
						skin: 'msg',
						time: 2000
					});
					return false;
				}

				let SiOrderDeID = $(".rowBoxContainer #productBox" + currScanRow).find(".FSiOrderDeID").text();
				let totalQty = $(".rowBoxContainer #productBox" + currScanRow).find(".totalQty").text();
				let obj = {};
				obj.FBoxCode = scanData.recode;
				obj.SiOrderDeID = SiOrderDeID == 'undefined' || SiOrderDeID == 'null' ? 0 :
					SiOrderDeID;
				console.log(JSON.stringify(obj));
				APP.jqueryAjax('YZ_CGTH', obj, function(res) {
					console.log(JSON.stringify(res));
					if (res.ds[0].status == 500) {
						layer.open({
							content: res.ds[0].msg,
							skin: 'msg',
							time: 2000
						});
					} else {
						vm.tabIndex = 1;
						if (currScanRow > -1) {
							vm.scanDisabled = true;
							var isExistsQrCode = vm.verifyQrCode(scanData); // 1.重复扫码验证(页面)
							if (!isExistsQrCode) {
								var codeInfo = {
									qrCode: res.ds[0].FBoxCode, //箱码
									qty: res.ds[0].FQty, //每箱数量
									fid: res.ds[0].FStorageID, //库位ID
									fname: res.ds[0].FStorageCode, //库位名称
									fbatchno: res.ds[0].FBatchNo, //批次号
									wid: res.ds[0].FWarehouseID,
									wname: res.ds[0].FWarehouseName,
									ISCF: res.ds[0].ISCF, //
								}
								if ($('.rowBoxContainer #ProductID' + currScanRow).text() != res.ds[0].ProductID) {
									vm.scanDisabled = false;
									layer.open({
										content: '当前扫码行与箱码产品不一致!',
										skin: 'msg',
										time: 2000
									});
								} else {
									vm.insertQrCode(codeInfo, currScanRow);
								}
							} else {
								vm.scanDisabled = false;
								layer.open({
									content: '请勿重复扫码!',
									skin: 'msg',
									time: 2000
								});
							}
						}

					}
				})
			} else if (scanData.type == '产品批次码') {
				vm.scanDisabled = true;
				let obj = {
					FBatchCode: scanData.recode,
					SiOrderID: vm.form.SiOrderID
				}
				console.log(JSON.stringify(obj));
				APP.jqueryAjax('YZ_CGTH_CPPCM', obj, function(res) {
					vm.scanDisabled = false;
					if (res.ds[0].status == 500) {
						layer.open({
							content: res.ds[0].msg,
							skin: 'msg',
							time: 2000
						});
					} else {
						vm.tabIndex = 2;

						let rowObj = {
							ProductID: res.ds[0].ProductID,
							ProductName: res.ds[0].ProductName,
							FBatchNo: res.ds[0].FBatchNo,
							SiOrderDeID: res.ds[0].SiOrderDeID
						}
						vm.insertProductFBatchNoRow(rowObj);
					}
				})
			} else {
				vm.scanDisabled = true;
				vm.scanDisabled = false;
				layer.open({
					content: '请扫描正确的条码',
					skin: 'msg',
					time: 2000
				});

			}
		}

		var vm = new Vue({
			el: '#app',
			data: {
				showLoading: false,
				ifConfirm: false,
				scanDisabled: false,
				titleName: '',
				showDate: false,
				currentDate: new Date(),
				isPDA: false,
				// scanRow: 0,
				EBoxNum: '',
				form: {
					FStockID: 0,
					FWarehouseID: 0,
					FWarehouseName: '',
					FSupplyID: 0,
					FSupplyName: '',
					FStorageID: 0,
					FStorageCode: '',
					FDate: APP.getFormatDate2('yyyy-MM-dd'),
					BillNO: '', //退货单号
					Approve: 0,
					SiOrderID: 0,
				},
				formDetail: [],
				active: 0,
				SiOrderDetail: [],
				immersed: 0,
				baseScreenObj: {}, //弹窗选择列表参数
				activeNames: ['1'],
				tabIndex: 1, // 子表页签
				isPDA: false,
				safeBottom: 0
			},

			created: function() {

			},

			mounted() {

			},

			methods: {

				// 获取单据详情
				SetServiceIP(IP) { // 从外部获取账套IP地址
					var that = this
					// console.log(IP);
					let data = JSON.parse(IP);
					APP.serverIP(data.serverIP);
					APP.IPAgreement(data.IPAgreement);
					that.form.FStockID = data.ID;
					that.titleName = data.menu.APFunName + '详情';
					that.isPDA = data.isPDA;
					that.safeBottom = data.safeBottom;
					$('.head').css({
						'padding-top': data.safeTop + 'px'
					})
					if (data.safeBottom > 0) {
						$('.bottom').css({
							'padding-bottom': data.safeBottom + 'px'
						});
					}
					setTimeout(() => {
						if (that.form.FStockID) {
							that.getPageData();
						}
					}, 300)
				},

				// 设置下拉返回
				SetChoiceData(content) {
					let selectItem = JSON.parse(content);
					// console.log(JSON.stringify(selectItem));

					if (selectItem.type == '产品') {
						vm.insertProductRow(selectItem.data);
					}

					if (selectItem.type == '仓库') {
						if (vm.form.FWarehouseName != selectItem.data.FWarehouseName) {
							vm.form.FWarehouseID = selectItem.data.FWarehouseID;
							vm.form.FWarehouseName = selectItem.data.FWarehouseName;

							vm.form.FStorageID = 0;
							vm.form.FStorageCode = '';
						}
					}

					if (selectItem.type == '供应商') {
						if (vm.form.FSupplyName != selectItem.data.SupplyName) {
							vm.form.FSupplyID = selectItem.data.FSupplyID;
							vm.form.FSupplyName = selectItem.data.SupplyName;
						}
					}

					if (selectItem.type == '产品批次_库位') {
						let productBoxID = $('.rowFBatchNoContainer #' + new_selectFname).parents(".productBox").attr(
							'id').replace(
							'productBox', '');
						console.log(productBoxID);
						let verify = vm.verifyMatchArr(selectItem.data, productBoxID)
						console.log(verify)
						if (!verify) {
							console.log(new_selectFname)
							console.log($('.rowFBatchNoContainer #' + new_selectFname).attr('id'))
							let objNo = $('.rowFBatchNoContainer #' + new_selectFname).attr('id').replace('pos', '');
							$(".rowFBatchNoContainer #FWarehouseID" + objNo).text(selectItem.data.FWarehouseID);
							$(".rowFBatchNoContainer #ware" + objNo).text(selectItem.data.FWarehouseName);
							$(".rowFBatchNoContainer #FStorageID" + objNo).text(selectItem.data.FStorageID);
							$(".rowFBatchNoContainer #pos" + objNo).text(selectItem.data.FStorageCode);
							$(".rowFBatchNoContainer #qty" + objNo).text(selectItem.data.KCKQTY);
							let productBoxID = $('.rowFBatchNoContainer #' + new_selectFname).parents(".productBox")
								.attr('id')
								.replace('productBox', '');
							vm.calcRowTotal(productBoxID, 2);
						}

					}
				},
				verifyMatchArr(matchArr, productBoxID) {
					console.log(JSON.stringify(matchArr))
					let verify = false;
					let matchRows = $(".rowFBatchNoContainer #codeBox" + productBoxID).children('div.BoxCodeDetail');
					for (let i = 0; i < matchRows.length; i++) {
						let FWarehouseID = matchRows.eq(i).find('.ware-value').text();
						let FStorageID = matchRows.eq(i).find('.pos-value').text();
						console.log(FWarehouseID)
						console.log(FStorageID)
						if (matchArr.FWarehouseID == FWarehouseID && matchArr.FStorageID == FStorageID) {
							verify = true;

							break;
						}
					};
					return verify;
				},
				SetScanData(result) {
					let scanData = scanTransf(result);
					console.log(JSON.stringify(scanData));
					scanHandler(scanData);
				},

				rowOpenScan() {
					var that = this;
					that.openScan();
				},
				openScan() {
					this.sendMessage('openCamera', null);
				},
				//生成产品批次行
				insertProductFBatchNoRow(productInfo) {
					//验证当前增加产品行是否已存在,存在则跳过
					var isExistsRow = vm.verifyDupProductRow(2, productInfo);

					if (!isExistsRow) {
						let seqNo = new_seqNo;
						var productBox =
							'<div class=\'flex-box flex-direction-c productBox\' id=\'productBox' +
							seqNo +
							'\'> \
				                         <div class=\'flex-box title-bg\'><div class=\'flex-main rowProduct\' id=\'rowProduct' +
							seqNo + '\'>' + productInfo.ProductName + '</div> \
				                         <div class=\'delete-img\' id=\'rowDel' + seqNo + '\'><img src=\'../../image/sc.png\' /></div> \
										 <div class=\'FSiOrderDeID hideElements\' id=\'FSiOrderDeID' + seqNo + '\'>' +
							productInfo.SiOrderDeID + '</div>\
				                         <div class=\'pid-value hideElements\' id=\'ProductID' + seqNo + '\'>' +
							productInfo.ProductID + '</div></div> \
				                         <div class=\'flex-box flex-direction-r productTotal\'>  \
				                             <div class=\'flex-box flex-direction-r total-left\'>  \
				                                 <div class=\'flex-main\'>批次号:</div>  \
				                                 <div class=\'flex-box flex-main totalBoxNum FBatchNo\' id=\'FBatchNo' +
							seqNo + '\'>' + productInfo.FBatchNo + '</div>   \
				                             </div>  \
				                             <div class=\'flex-box flex-direction-r total-right\'> \
				                                 <div class=\'flex-main\'>合计数量:</div>   \
				                                 <div class=\'flex-box flex-main totalQty\' id=\'totalQty' + seqNo + '\'></div>  \
				                             </div>  \
				                         </div>  \
				                         <div class=\'flex-box flex-direction-r codeBox-title\'><div class=\'delCode-title\'>删除</div> \
				                         <div class=\'ware-title\'>仓库</div><div class=\'pos-title\'>库位</div><div class=\'qty-title\'>数量</div></div> \
				                         <div class=\'flex-box flex-direction-c codeBox\' id=\'codeBox' + seqNo + '\'></div> \
				                         </div>'
						$(".rowFBatchNoContainer").prepend(productBox);
						vm.setNewScanRow(seqNo); //当前扫码行置第一位

						// if (vm.form.FStockID != '') {
						//     $("#rowDel" + seqNo).hide()
						// }
						//已审核的单据隐藏删除按钮                   
						if (vm.form.Approve) {
							$(".rowFBatchNoContainer #rowDel" + seqNo).hide()
						}

						//产品行点击选中
						$(".rowFBatchNoContainer #productBox" + seqNo).click(function() {
							var productBoxNo = $(this).attr('id').replace('productBox', '');
							$(".rowFBatchNoContainer #productBox" + productBoxNo).addClass('b-p');
							vm.setNewScanRow(productBoxNo);
						})

						//产品行删除
						$(".rowFBatchNoContainer #rowDel" + seqNo).click(function() {
							var rowDelNo = $(this).attr('id').replace('rowDel', '');
							vm.$dialog.confirm({
								title: '提示',
								message: '是否删除?',
							}).then(function() {
								$(".rowFBatchNoContainer #productBox" + rowDelNo)
									.remove();
								vm.setNewScanRow(-1);
							}).catch(function() {

							});

						})

						new_seqNo += 1;
					} else {
						// layer.open({
						// 	content: '产品已存在,请勿重复添加!',
						// 	skin: 'msg',
						// 	time: 2000
						// });
					}

					if (new_currScanRow > -1) {
						$('.detail-content div .button').remove();
					}
				},
				insertFBatchNoQrCode(codeInfo, existsProductSeqNo) {

					//获取当前产品行箱码最大序号
					var currProductMaxCodeIndex = 0;
					if ($(".rowFBatchNoContainer #codeBox" + existsProductSeqNo).children().length) {
						currProductMaxCodeIndex = $(".rowFBatchNoContainer #codeBox" +
								existsProductSeqNo)
							.children(
								':first-child').find(
								'.codeDelBtn').attr('id').replace('codeDelBtn' + existsProductSeqNo,
								'');
					}
					currProductMaxCodeIndex = parseInt(currProductMaxCodeIndex) + 1;

					//1.5增加批次号显示进行的修改
					var codeHtml = '<div class=\'flex-box flex-direction-r BoxCodeDetail boxCodeShow\'>   \
				                        <div class=\'delCode-content codeDelBtn delete-img\' id=\'codeDelBtn' +
						existsProductSeqNo + currProductMaxCodeIndex + '\'><img src=\'../../image/delete.png\'/></div>    \
				                        <div class=\'ware-content\' id=\'ware' + existsProductSeqNo +
						currProductMaxCodeIndex + '\'>' + codeInfo.FWarehouseName + '</div>  \
										<div class=\'ware-value hideElements\' id=\'FWarehouseID' + existsProductSeqNo +
						currProductMaxCodeIndex + '\'>' + codeInfo.FWarehouseID + '</div> \
				                        <div class=\'pos-value hideElements\' id=\'FStorageID' + existsProductSeqNo +
						currProductMaxCodeIndex + '\'>' + codeInfo.fid + '</div> \
				                        <div class=\'pos-content\' id=\'pos' + existsProductSeqNo +
						currProductMaxCodeIndex + '\'>' + codeInfo.fname + '</div> \
				                       <div contenteditable=\'true\' class=\'qty-content\' id=\'qty' + existsProductSeqNo +
						currProductMaxCodeIndex + '\'>' + codeInfo.qty + '</div>  \
				                    </div> ';
					$('.rowFBatchNoContainer #productBox' + existsProductSeqNo + ' .codeBox').prepend(
						codeHtml);
					//已审核的单据隐藏箱码删除,取消数量可编辑
					if (vm.form.Approve) {
						$(".rowFBatchNoContainer #qty" + existsProductSeqNo + currProductMaxCodeIndex).attr(
							'contenteditable',
							false)
						$('.rowFBatchNoContainer .delCode-title').hide();
						$('.rowFBatchNoContainer .delCode-content').hide();
					}
					$(".rowFBatchNoContainer #qty" + existsProductSeqNo + currProductMaxCodeIndex)
						.blur(
							function() {
								vm.calcRowTotal(existsProductSeqNo, 2);
							})
					$(".rowFBatchNoContainer #codeDelBtn" + existsProductSeqNo +
							currProductMaxCodeIndex)
						.click(
							function() {
								//1.5增加批次号显示进行的修改
								var currClickBtnID = $(this).attr('id');
								vm.$dialog.confirm({
									title: '提示',
									message: '是否删除该行?',
								}).then(function() {

									console.log(JSON.stringify(currClickBtnID));

									vm.deleteQrCode(existsProductSeqNo,
										currProductMaxCodeIndex,
										currClickBtnID, 2);
								}).catch(function() {

								});
							})

					$(".rowFBatchNoContainer #pos" + existsProductSeqNo + currProductMaxCodeIndex)
						.click(
							function() {
								if (!vm.form.Approve) {
									new_selectFid = $(".rowFBatchNoContainer #FStorageID" +
										existsProductSeqNo +
										currProductMaxCodeIndex).attr(
										'id');
									new_selectFname = $(this).attr('id');
									console.log(JSON.stringify(new_selectFname));
									console.log(JSON.stringify(new_selectFid));
									vm.openBaseScreen('产品批次_库位');
								}
							})
					vm.calcRowTotal(existsProductSeqNo, 2);
					vm.scanDisabled = false;
				},
				//生成产品行
				insertProductRow(productInfo) {
					console.log(JSON.stringify(productInfo))
					//验证当前增加产品行是否已存在,存在则跳过
					var isExistsRow = vm.verifyDupProductRow(1, productInfo);
					console.log(isExistsRow);
					if (!isExistsRow) {
						//
						if (vm.form.BillNO) {
							vm.SiOrderDetail.push({
								ProductName: productInfo.ProductName,
								UnitName: productInfo.UnitName,
								Qty: productInfo.Qty,
								WCQty: productInfo.WCQty,
								SYQty: productInfo.SYQty,
								allStorage: productInfo.allStorage
							})
						}
						//console.log(JSON.stringify(vm.SiOrderDetail));
						//
						var productBox =
							'<div class=\'flex-box flex-direction-c productBox\' id=\'productBox' + seqNo +
							'\'> \
                                         <div class=\'flex-box title-bg\'><div class=\'flex-main rowProduct\' id=\'rowProduct' +
							seqNo + '\'>' + productInfo.ProductName + '</div> \
                                         <div class=\'delete-img\' id=\'rowDel' + seqNo + '\'><img src=\'../../image/sc.png\' /></div> \
                                         <div class=\'hideElements FSiOrderDeID\' id=\'FSiOrderDeID' + seqNo + '\'>' +
							productInfo.SiOrderDeID + '</div> \
                                         <div class=\'pid-value hideElements\' id=\'ProductID' + seqNo + '\'>' +
							productInfo.ProductID + '</div></div> \
                                         <div class=\'flex-box flex-direction-r productTotal\'>  \
                                             <div class=\'flex-box flex-direction-r total-left\'>  \
                                                 <div class=\'flex-main\'>合计箱数:</div>  \
                                                 <div class=\'flex-box flex-main totalBoxNum\' id=\'totalBoxNum' +
							seqNo + '\'></div>   \
                                             </div>  \
                                             <div class=\'flex-box flex-direction-r total-right\'> \
                                                 <div class=\'flex-main\'>合计数量:</div>   \
                                                 <div class=\'flex-box flex-main totalQty\' id=\'totalQty' + seqNo + '\'></div>  \
                                             </div>  \
                                         </div>  \
                                         <div class=\'flex-box flex-direction-r productTotal SYQty\'>  \
                                             <div class=\'flex-box flex-direction-r total-left1\'>  \
                                                 <div class=\'flex-main\'>可退数量:</div>  \
                                                 <div class=\'flex-box flex-main totalBoxNum\' id=\'SYQty' + seqNo +
							'\'>' + productInfo.SYQty + '</div>   \
                                             </div>  \
                                         </div>  \
                                         <div class=\'flex-box flex-direction-r codeBox-title\'><div class=\'delCode-title\'>删除</div> \
                                         <div class=\'boxCode-title\'>箱码</div><div class=\'qty-title\'>数量</div><div class=\'ware-title\'>仓库</div><div class=\'pos-title\'>库位</div></div> \
                                         <div class=\'flex-box flex-direction-c codeBox\' id=\'codeBox' + seqNo + '\'></div> \
                                       </div>'
						$(".rowBoxContainer").prepend(productBox);
						vm.setScanRow(seqNo); //当前扫码行置第一位

						//已审核的单据隐藏删除按钮
						if (vm.form.Approve || vm.form.BillNO) {
							$(".rowBoxContainer #rowDel" + seqNo).hide()
						}

						//没有退货单隐藏可入库数
						if (!vm.form.BillNO) {
							$(".rowBoxContainer .SYQty").hide()
						}

						//产品行点击选中
						$(".rowBoxContainer #productBox" + seqNo).click(function() {
							var productBoxNo = $(this).attr('id').replace('productBox', '');
							$(".rowBoxContainer #productBox" + productBoxNo).addClass('b-p');
							vm.setScanRow(productBoxNo);
						})
						//产品行删除
						$(".rowBoxContainer #rowDel" + seqNo).click(function() {
							var rowDelNo = $(this).attr('id').replace('rowDel', '');
							$(".rowBoxContainer #productBox" + rowDelNo).remove();
							vm.setScanRow(-1);
						})

						seqNo += 1;
					} else {
						layer.open({
							content: '产品已存在,请勿重复添加!',
							skin: 'msg',
							time: 2000
						});
					}


					if (currScanRow > -1) {
						$('.detail-content div .button').remove();
					}
				},

				//验证产品行是否重复添加
				verifyDupProductRow(type, productInfo) {
					var isExistsProductRow = false;
					if (type == 1) {
						var matchRows = $(".rowBoxContainer").find('.rowProduct');
						var SiOrderDeIDRows = $(".rowBoxContainer").find('.SiOrderDeID');
						//产品信息是否存在(ProductName由产品编码、名称、规格组成)
						if (matchRows.length) {
							var matchProductCodes = [];
							for (var i = 0; i < matchRows.length; i++) {
								if (matchRows.eq(i).text() == productInfo.ProductName) {
									if (!vm.form.BillNO) {
										isExistsProductRow = true;
										break;
									}
									if (SiOrderDeIDRows.eq(i).text() == productInfo.SiOrderDeID) {
										isExistsProductRow = true;
										break;
									}
								}
							}
						}
						return isExistsProductRow;
					} else if (type == 2) {
						var matchRows = $(".rowFBatchNoContainer").find('.rowProduct');
						var matchRows1 = $(".rowFBatchNoContainer").find('.FBatchNo');
						if (matchRows.length) {
							var matchProductCodes = [];
							for (var i = 0; i < matchRows.length; i++) {
								if (matchRows.eq(i).text() == productInfo.ProductName && matchRows1.eq(i).text() ==
									productInfo.FBatchNo) {
									isExistsProductRow = true;
									break;
								}
							}
						}
						return isExistsProductRow;
					}
				},

				//箱码验证
				verifyQrCode(scanData) {
					var isExistsQrCode = false;
					var matchCodes = $(".rowBoxContainer").find('.boxCode-content');
					if (matchCodes.length) {
						for (var i = 0; i < matchCodes.length; i++) {
							if (matchCodes.eq(i).text() == scanData.recode) {
								isExistsQrCode = true;
								break;
							}
						}
					}
					return isExistsQrCode;
				},

				//插入箱码
				insertQrCode(codeInfo, existsProductSeqNo) {
					//获取当前产品行箱码最大序号
					var currProductMaxCodeIndex = 0;
					if ($(".rowBoxContainer #codeBox" + existsProductSeqNo).children().length) {
						//currProductMaxCodeIndex = $("#codeBox" + existsProductSeqNo).children(':last-child').find('.codeDelBtn').attr('id').replace('codeDelBtn', '');
						currProductMaxCodeIndex = $(".rowBoxContainer #codeBox" + existsProductSeqNo).children(
								':first-child')
							.find('.codeDelBtn').attr('id').replace('codeDelBtn' + existsProductSeqNo, '');
						console.log(JSON.stringify(currProductMaxCodeIndex));
					}
					currProductMaxCodeIndex = parseInt(currProductMaxCodeIndex) + 1;
					console.log(JSON.stringify(currProductMaxCodeIndex));

					//箱码行
					var codeHtml = '<div class=\'flex-box flex-direction-r BoxCodeDetail boxCodeShow\'>   \
                                         <div class=\'delCode-content codeDelBtn delete-img\' id=\'codeDelBtn' +
						existsProductSeqNo + currProductMaxCodeIndex + '\'><img src=\'../../image/delete.png\'/></div>    \
                                         <div class=\'boxCode-content\' id=\'code' + existsProductSeqNo +
						currProductMaxCodeIndex + '\'>' + codeInfo.qrCode + '</div>  \
                                         <div contenteditable=\'true\' class=\'qty-content\' id=\'qty' +
						existsProductSeqNo + currProductMaxCodeIndex + '\'>' + codeInfo.qty + '</div>  \
										<div class=\'ware-value hideElements\' id=\'FWarehouseID' +
						existsProductSeqNo + currProductMaxCodeIndex + '\'>' + codeInfo.wid + '</div> \
						                <div class=\'ware-content\' id=\'ware' + existsProductSeqNo +
						currProductMaxCodeIndex + '\'>' + codeInfo.wname + '</div> \
                                         <div class=\'pos-value hideElements\' id=\'FStorageID' + existsProductSeqNo +
						currProductMaxCodeIndex + '\'>' + codeInfo.fid + '</div> \
										<div class=\'fbatch hideElements\' id=\'FBatchNo' + existsProductSeqNo +
						currProductMaxCodeIndex + '\'>' + codeInfo.fbatchno + '</div> \
                                         <div class=\'ISCF hideElements\' id=\'ISCF' + existsProductSeqNo +
						currProductMaxCodeIndex + '\'>' + codeInfo.ISCF + '</div> \
                                         <div class=\'pos-content\' id=\'pos' + existsProductSeqNo +
						currProductMaxCodeIndex + '\'>' + codeInfo.fname + '</div> \
									  </div> \
									     <div class=\'flex-box flex-direction-r BoxCodeFBatchNo boxCodeShow\' id=\'fbatch' +
						existsProductSeqNo + currProductMaxCodeIndex + '\'>   \
									      <div>' + '批次号：' + '<span>' +
						codeInfo.fbatchno + '</span>' + '</div> \
									      </div>';
					$('.rowBoxContainer #productBox' + existsProductSeqNo + ' .codeBox').prepend(codeHtml);
					//已审核的单据隐藏箱码删除,取消数量可编辑
					if (vm.form.Approve) {
						$(".rowBoxContainer #qty" + existsProductSeqNo + currProductMaxCodeIndex).attr(
							'contenteditable',
							false)
						$('.rowBoxContainer .delCode-title').hide();
						$('.rowBoxContainer .delCode-content').hide();
					}
					$(".rowBoxContainer #qty" + existsProductSeqNo + currProductMaxCodeIndex).blur(function() {
						vm.calcRowTotal(existsProductSeqNo);
					})
					$(".rowBoxContainer #codeDelBtn" + existsProductSeqNo + currProductMaxCodeIndex).click(
						function() {
							var currClickBtnID = $(this).attr('id');
							console.log(JSON.stringify(currClickBtnID));
							let ISCF = $(".rowBoxContainer #ISCF" + existsProductSeqNo + currProductMaxCodeIndex)
								.text();
							console.log(JSON.stringify(ISCF));
							if (ISCF == 1) {
								let obj = {};
								obj.FBoxCode = $(".rowBoxContainer #code" + existsProductSeqNo +
										currProductMaxCodeIndex)
									.text();
								obj.FStockID = vm.form.FStockID;
								console.log(JSON.stringify(obj));
								vm.$dialog.confirm({
									title: '提示',
									message: '是否删除此拆分后的箱码?',
								}).then(function() {
									APP.jqueryAjax('DEL_CFXM', obj, function(res) {
										if (res.ds[0].status == 500) {
											layer.open({
												content: res.ds[0].msg,
												skin: 'msg',
												time: 2000
											});
										} else {
											vm.$dialog.alert({
												title: '提示',
												message: '删除成功!',
											}).then(function() {
												$(".rowBoxContainer #fbatch" +
														existsProductSeqNo +
														currProductMaxCodeIndex)
													.remove();
												vm.deleteQrCode(
													existsProductSeqNo,
													currProductMaxCodeIndex,
													currClickBtnID, 1);
												let matchCodes = $(
													".rowBoxContainer").find(
													'.boxCode-content');
												//let matchCodes1 = $(".rowBoxContainer").find('.qty-content');
												if (matchCodes.length) {
													for (var i = 0; i < matchCodes
														.length; i++) {
														if (matchCodes.eq(i)
															.text() == res.ds[0]
															.FYFBoxCode) {
															// matchCodes1.eq(i).text(Number(matchCodes1.eq(i).text()) + Number(res.ds[0].FYQTY));
															// vm.calcRowTotal(existsProductSeqNo);
															let FProductSeqNo =
																matchCodes.eq(i)
																.parents(
																	".productBox")
																.attr('id')
																.replace(
																	"productBox",
																	"");
															console.log(JSON
																.stringify(
																	FProductSeqNo
																))
															let curFBatchNoID = matchCodes
																.eq(i).attr('id').replace(
																	"code", "")
															$(".rowBoxContainer #fbatch" +
																	curFBatchNoID)
																.remove();
															vm.deleteQrCode(
																FProductSeqNo,
																currProductMaxCodeIndex,
																matchCodes.eq(
																	i).attr(
																	'id'), 1);
															break;
														}
													}
												}
											})
										}
									})
								}).catch(function() {

								});
							} else {
								vm.$dialog.confirm({
									title: '提示',
									message: '是否删除该箱码?',
								}).then(function() {
									$(".rowBoxContainer #fbatch" + existsProductSeqNo +
											currProductMaxCodeIndex)
										.remove();
									vm.deleteQrCode(existsProductSeqNo, currProductMaxCodeIndex,
										currClickBtnID, 1);
								}).catch(function() {

								});
							}
						})
					// $("#pos" + existsProductSeqNo + currProductMaxCodeIndex).click(function () {
					//     selectFid = $("#FStorageID" + existsProductSeqNo + currProductMaxCodeIndex).attr('id');
					//     selectFname = $(this).attr('id');
					//     console.log(JSON.stringify(selectFname));
					//     console.log(JSON.stringify(selectFid));
					//     vm.openBaseScreen('箱码库位');

					// })

					vm.calcRowTotal(existsProductSeqNo, 1);
					vm.scanDisabled = false;
				},

				//删除箱码
				deleteQrCode(existsProductSeqNo, currProductMaxCodeIndex, currClickBtnID, type) {
					let name = ''
					if (type == 1) {
						name = '.rowBoxContainer'
					} else if (type == 2) {
						name = '.rowFBatchNoContainer'
					}
					$(name + ' #' + currClickBtnID).parent().remove();
					//当前产品箱码数量为0时 删除当前产品节点
					//当有退货单号时 删除最后一个箱码不会删除当前产品节点
					if ($(name + " #codeBox" + existsProductSeqNo).children().length == 0 && vm.form.BillNO == '') {
						$(name + " #productBox" + existsProductSeqNo).remove();
					}
					vm.calcRowTotal(existsProductSeqNo, type);
				},

				//设置扫描行
				setScanRow(existsProductSeqNo) {
					if (currScanRow > -1 && existsProductSeqNo == -1) {
						var productRows = $('.rowBoxContainer').children().length;
						if (productRows) {
							var firstRow = $('.rowBoxContainer').children(':first-child');
							var firstRowIndex = parseInt(firstRow.attr('id').replace('productBox', ''));
							existsProductSeqNo = firstRowIndex;
						} else {
							currScanRow = -1;
							layer.open({
								content: '已全部清空!',
								skin: 'msg',
								time: 2000
							});
						}
					} else if (currScanRow > -1 && currScanRow != existsProductSeqNo && existsProductSeqNo > -
						1) {
						$(".rowBoxContainer #productBox" + currScanRow).removeClass('b-p');
						$(".rowBoxContainer #productBox" + currScanRow).addClass('b-p-t');
					}
					$(".rowBoxContainer #productBox" + existsProductSeqNo).removeClass('b-p-t');
					$(".rowBoxContainer #productBox" + existsProductSeqNo).addClass('b-p');
					currScanRow = existsProductSeqNo; //更新当前扫码产品行
				},
				setNewScanRow(existsProductSeqNo) {
					if (new_currScanRow > -1 && existsProductSeqNo == -1) {
						var productRows = $('.rowFBatchNoContainer').children().length;
						if (productRows) {
							var firstRow = $('.rowFBatchNoContainer').children(':first-child');
							var firstRowIndex = parseInt(firstRow.attr('id').replace('productBox',
								''));
							existsProductSeqNo = firstRowIndex;
						} else {
							new_currScanRow = -1;
							layer.open({
								content: '已全部清空!',
								skin: 'msg',
								time: 2000
							});
						}
					} else if (new_currScanRow > -1 && new_currScanRow != existsProductSeqNo &&
						existsProductSeqNo > -
						1) {
						$(".rowFBatchNoContainer #productBox" + new_currScanRow).removeClass('b-p');
						$(".rowFBatchNoContainer #productBox" + new_currScanRow).addClass('b-p-t');
					}
					$(".rowFBatchNoContainer #productBox" + existsProductSeqNo).removeClass('b-p-t');
					$(".rowFBatchNoContainer #productBox" + existsProductSeqNo).addClass('b-p');
					new_currScanRow = existsProductSeqNo; //更新当前扫码产品行
				},
				//合计扫码/箱数计算
				calcRowTotal(existsProductSeqNo, type) {
					let name = ''
					if (type == 1) {
						name = '.rowBoxContainer'
					} else if (type == 2) {
						name = '.rowFBatchNoContainer'
					}
					var matchItems = $(name + ' #codeBox' + existsProductSeqNo).find('.qty-content');
					var totalBoxNum = 0,
						totalQty = 0;
					for (var i = 0; i < matchItems.length; i++) {
						totalBoxNum += 1;
						totalQty += Number(matchItems.eq(i).text());
					}
					$(name + ' #totalBoxNum' + existsProductSeqNo).text('' + totalBoxNum + '');
					$(name + ' #totalQty' + existsProductSeqNo).text('' + totalQty.toFixed(2) + '');
				},

				//获取历史单据详情
				getPageData() {
					var that = this;
					APP.jqueryAjax('CGTH_MXList', {
						FStockID: that.form.FStockID
					}, function(res) {
						//console.log(JSON.stringify(res))
						if (res.ds.length) {

							vm.form.FSupplyID = res.ds[0].FSupplyID;
							vm.form.FSupplyName = res.ds[0].SupplyName;

							vm.form.FDate = res.ds[0].FDate;
							vm.form.BillNO = res.ds[0].BillNO;
							vm.form.Approve = res.ds[0].Approve;
							vm.form.SiOrderID = res.ds[0].SiOrderID;

							var curProductID = 0; //当前产品
							var SiOrderDeID = 0; //退货单子表ID
							var codeInfo = null; //箱码信息
							vm.SiOrderDetail = [];
							for (var i = 0; i < res.ds.length; i++) {
								codeInfo = res.ds[i];
								if (curProductID != res.ds[i].ProductID) {
									curProductID = res.ds[i].ProductID
									vm.insertProductRow(codeInfo);
									vm.generatePageDe(curProductID, codeInfo);
								} else {
									//插入箱码
									//vm.generatePageDe(curProductID, codeInfo);
									if (SiOrderDeID != res.ds[i].SiOrderDeID) {
										SiOrderDeID = res.ds[i].SiOrderDeID;
										vm.insertProductRow(codeInfo);
										//插入箱码
										vm.generatePageDe(curProductID, codeInfo);
									} else {
										//插入箱码
										vm.generatePageDe(curProductID, codeInfo);
									}
								}
							}
						}

						if (res.ds1.length) {

							vm.form.FSupplyID = res.ds[0].FSupplyID;
							vm.form.FSupplyName = res.ds[0].SupplyName;

							vm.form.FDate = res.ds1[0].FDate;
							vm.form.BillNO = res.ds[0].BillNO;
							vm.form.Approve = res.ds1[0].Approve;
							vm.form.SiOrderID = res.ds[0].SiOrderID;

							let curProductID = 0;
							let curFBatchNo = '';
							let codeInfo = null;
							for (let i = 0; i < res.ds1.length; i++) {

								codeInfo = res.ds1[i];
								if (curProductID != res.ds1[i].ProductID || curFBatchNo != res
									.ds1[i]
									.FBatchNo) {
									curProductID = res.ds1[i].ProductID
									curFBatchNo = res.ds1[i].FBatchNo
									vm.insertProductFBatchNoRow(codeInfo);
									vm.generatePageDeNew(curProductID, curFBatchNo, codeInfo);
								} else {
									vm.generatePageDeNew(curProductID, curFBatchNo, codeInfo);
								}
							}
						}
					})
				},
				generatePageDeNew(curProductID, curFBatchNo, codeInfo) {

					var matchCodes = $(".rowFBatchNoContainer").find('.pid-value');
					var matchCodes1 = $(".rowFBatchNoContainer").find('.FBatchNo');
					var obj = null;
					if (matchCodes.length) {
						for (var i = 0; i < matchCodes.length; i++) {
							if (matchCodes.eq(i).text() == curProductID && matchCodes1.eq(i).text() ==
								curFBatchNo) {
								var rowNo = matchCodes.eq(i).attr('id').replace('ProductID', '');
								obj = {
									qty: codeInfo.FQty,
									fid: codeInfo.FStorageID,
									fname: codeInfo.FStorageCode,
									FWarehouseName: codeInfo.FWarehouseName,
									FWarehouseID: codeInfo.FCKWarehouseID,
								}

								vm.insertFBatchNoQrCode(obj, rowNo)
							}
						}
					}
				},
				generatePageDe(curProductID, codeInfo) {
					var matchCodes = $(".rowBoxContainer").find('.pid-value');
					var matchCodes1 = $(".rowBoxContainer").find('.FSiOrderDeID');
					var obj = null;
					if (matchCodes.length) {
						for (var i = 0; i < matchCodes.length; i++) {
							if (matchCodes.eq(i).text() == curProductID && matchCodes1.eq(i).text() ==
								codeInfo.SiOrderDeID) {
								var rowNo = matchCodes.eq(i).attr('id').replace('ProductID', '');
								//console.log(JSON.stringify(rowNo))
								obj = {
									qrCode: codeInfo.FBoxCode,
									qty: codeInfo.FQty,
									fid: codeInfo.FStorageID,
									fname: codeInfo.FStorageCode,
									fbatchno: codeInfo.FBatchNo,
									wid: codeInfo.FCKWarehouseID,
									wname: codeInfo.FWarehouseName,
									ISCF: codeInfo.ISCF, //
								}
								vm.insertQrCode(obj, rowNo)
							}
						}
					}
				},

				//单据提交
				confirmSub() {
					if (!vm.form.FSupplyName) {
						layer.open({
							content: '请选择供应商',
							skin: 'msg',
							time: 2000
						});
						return false;
					}

					if (!$('.rowBoxContainer .boxCodeShow').length && !$('.rowFBatchNoContainer .boxCodeShow')
						.length) {
						layer.open({
							content: '提交产品箱码和产品批次码不能同时为空!!!',
							skin: 'msg',
							time: 2000
						});
						return false;
					}

					//遍历产品行拼接数据
					var matchRows = $(".rowBoxContainer").children();
					var FWarehouseIDs = [],
						FSiOrderDeIDs = [],
						FBoxCodes = [],
						FStorageIDs = [],
						FProductIDs = [],
						FQtys = [],
						FBatchNos = []

					var matchRows1 = $(".rowFBatchNoContainer").children();
					var FWarehouseIDs1 = [],
						FStorageIDs1 = [],
						FProductIDs1 = [],
						FQtys1 = [],
						FBatchNos1 = [],
						FSiOrderDeIDs1 = []
					//产品编码是否存在
					//按理是需要判断所有产品行下的箱码行数都不为空 
					//实际是提交有箱码为空的产品行，该产品行会忽略

					if (matchRows.length || matchRows1.length) {
						var matchProductCodes = [];
						for (let i = 0; i < matchRows.length; i++) {
							let rowIndex = matchRows.eq(i).attr('id').replace('productBox', '');
							let FSiOrderDeID = $('.rowBoxContainer #FSiOrderDeID' + rowIndex).text();
							let ProductID = $('.rowBoxContainer #ProductID' + rowIndex).text();
							let matchQrCodes = $('.rowBoxContainer #codeBox' + rowIndex).children(
								'div.BoxCodeDetail');
							console.log(JSON.stringify(matchQrCodes.length))
							for (let j = 0; j < matchQrCodes.length; j++) {
								let codeInfo = matchQrCodes.eq(j);
								let code = codeInfo.find('.boxCode-content').text();
								let qty = codeInfo.find('.qty-content').text();
								let FBatchNo = codeInfo.find('.fbatch').text();
								let fstorageid = codeInfo.find('.pos-value').text();
								let fwarehouseid = codeInfo.find('.ware-value').text();

								console.log(JSON.stringify(FSiOrderDeID));
								if (FSiOrderDeID == undefined || FSiOrderDeID == 'undefined' ||
									FSiOrderDeID == 'null') {
									FSiOrderDeIDs.push(0);
								} else {
									FSiOrderDeIDs.push(FSiOrderDeID);
								}

								FWarehouseIDs.push(fwarehouseid);
								FProductIDs.push(ProductID);
								FBoxCodes.push(code);
								FQtys.push(qty);
								FBatchNos.push(FBatchNo);
								FStorageIDs.push(fstorageid);
							}
						}

						for (let i = 0; i < matchRows1.length; i++) {
							let rowIndex = matchRows1.eq(i).attr('id').replace('productBox', '');
							let ProductID = $('.rowFBatchNoContainer #ProductID' + rowIndex).text();
							let FBatchNo = $('.rowFBatchNoContainer #FBatchNo' + rowIndex).text();
							let FSiOrderDeID = $('.rowFBatchNoContainer #FSiOrderDeID' + rowIndex).text();
							let matchQrCodes = $('.rowFBatchNoContainer #codeBox' + rowIndex)
								.children(
									'div.BoxCodeDetail'); //1.5增加批次号显示进行的修改
							for (let j = 0; j < matchQrCodes.length; j++) {
								let codeInfo = matchQrCodes.eq(j);
								let fwarehouseid = codeInfo.find('.ware-value').text();
								let qty = codeInfo.find('.qty-content').text();
								let fstorageid = codeInfo.find('.pos-value').text();

								console.log(JSON.stringify(FSiOrderDeID));
								if (FSiOrderDeID == undefined || FSiOrderDeID == 'undefined' ||
									FSiOrderDeID == 'null') {
									FSiOrderDeIDs1.push(0);
								} else {
									FSiOrderDeIDs1.push(FSiOrderDeID);
								}


								FProductIDs1.push(ProductID);
								FBatchNos1.push(FBatchNo);
								FWarehouseIDs1.push(fwarehouseid);
								FQtys1.push(qty);
								FStorageIDs1.push(fstorageid);

							}
						}


						var obj = {
							FStockID: vm.form.FStockID,
							FSupplyID: vm.form.FSupplyID,
							FSiOrderID: vm.form.SiOrderID,

							FWarehouseIDs: FWarehouseIDs.join(','),
							FProductIDs: FProductIDs.join(','),
							FBoxCodes: FBoxCodes.join(','),
							FQtys: FQtys.join(','),
							FBatchNos: FBatchNos.join(','),
							FStorageIDs: FStorageIDs.join(','),
							FSiOrderDeIDs: FSiOrderDeIDs.join(','),

							FProductIDs1: FProductIDs1.join(','),
							FWarehouseIDs1: FWarehouseIDs1.join(','),
							FQtys1: FQtys1.join(','),
							FStorageIDs1: FStorageIDs1.join(','),
							FBatchNos1: FBatchNos1.join(','),
							FSiOrderDeIDs1: FSiOrderDeIDs1.join(','),
						}

						console.log(JSON.stringify(obj));

						if (!vm.form.FStockID) {
							vm.$dialog.confirm({
								title: '提示',
								message: '是否提交此单据?',
							}).then(function() {
								if (vm.ifConfirm) return;
								vm.ifConfirm = true;

								APP.jqueryAjax('TJ_CGTH', obj, function(res) {
									vm.ifConfirm = false;
									if (res.ds[0].status == 500) {
										layer.open({
											content: res.ds[0].msg,
											skin: 'msg',
											time: 2000
										});
									} else {
										vm.$dialog.alert({
											title: '提示',
											message: '提交成功!',
										}).then(function() {
											uni.postMessage({
												data: {
													eventName: 'refreshList'
												}
											})
											vm.form.FStockID = res.ds[0].FStockID;
											$(".rowBoxContainer").children().remove();
											$(".rowFBatchNoContainer").children().remove();
											vm.getPageData();
										})
									}
								})
							}).catch(function() {

							});
						} else {
							vm.$dialog.confirm({
								title: '提示',
								message: '是否提交此编辑后的单据?',
							}).then(function() {
								if (vm.ifConfirm) return;
								vm.ifConfirm = true;

								APP.jqueryAjax('TJ_CGTH_EDIT', obj, function(res) {
									vm.ifConfirm = false;
									if (res.ds[0].status == 500) {
										layer.open({
											content: res.ds[0].msg,
											skin: 'msg',
											time: 2000
										});
									} else {
										vm.$dialog.alert({
											title: '提示',
											message: '提交成功!',
										}).then(function() {
											uni.postMessage({
												data: {
													eventName: 'refreshList'
												}
											})
											$(".rowBoxContainer").children().remove();
											$(".rowFBatchNoContainer").children().remove();
											vm.getPageData();
										})
									}
								})
							}).catch(function() {

							});
						}

					} else {
						layer.open({
							content: '提交产品不能为空!',
							skin: 'msg',
							time: 2000
						});
						return false;
					}

				},
				ApproveSubmit() {
					var that = this;
					let obj = {};
					obj.FStockID = that.form.FStockID;
					obj.isApprove = that.form.Approve ? 1 : 0;
					console.log(JSON.stringify(obj));
					vm.$dialog.confirm({
						title: '提示',
						message: that.form.Approve ? '是否取消审核此单据?' : '是否审核此单据?',
					}).then(function() {
						if (vm.ifConfirm) return;
						vm.ifConfirm = true;

						APP.jqueryAjax('CGTH_Approve', obj, function(res) {
							vm.ifConfirm = false;
							if (res.ds[0].status == 500) {
								layer.open({
									content: res.ds[0].msg,
									skin: 'msg',
									time: 2000
								});
							} else {
								vm.$dialog.alert({
									title: '提示',
									message: res.ds[0].msg,
								}).then(function() {
									if (!that.form.Approve) {
										uni.navigateBack();
									}
									uni.postMessage({
										data: {
											eventName: 'refreshList'
										}
									})
									$(".rowBoxContainer").children().remove();
									$(".rowFBatchNoContainer").children().remove();
									that.getPageData();
								})
							}
						})
					}).catch(function() {

					});

				},
				openDate(index) {
					var that = this;
					that.currentDate = new Date();
					that.showDate = true;
				},
				confirmDate(value) {
					var that = this;
					that.form.FDate = APP.getFormatDate2('yyyy-MM-dd', value);
					that.showDate = false;
				},
				cancelDate(value) {
					var that = this;
					that.form.FDate = '';
					that.showDate = false;
				},

				openBaseScreen(str) {
					let that = this;

					if (that.form.Approve) {
						return;
					}

					if (str == '产品') {
						vm.baseScreenObj = {
							allowClear: false,
							cmd: 'Droplist_Product',
							type: str,
							ListeningName: 'WmsEditChoice',
							refresherEnabled: false,
							serverSearch: {
								isPaging: false, //是否分页
								searchKey: 'ProductName',
								showText: 'ProductName', //查询结果显示的字段
								ChoiceDataKey: 'ProductID',
							},
							param: {
								ProductName: '',
							}
						}
					}

					if (str == '仓库') {

						vm.baseScreenObj = {
							allowClear: false,
							cmd: 'Down_WarehouseCP',
							type: str,
							ListeningName: 'WmsEditChoice',
							refresherEnabled: false,
							serverSearch: {
								isPaging: false, //是否分页
								showText: 'FWarehouseName', //查询结果显示的字段
								ChoiceDataKey: 'FWarehouseID',
								ChoiceDataData: vm.form.FWarehouseID
							},
							param: {

							}
						}
					}

					if (str == '供应商') {
						if (vm.form.BillNO) {
							return;
						}

						vm.baseScreenObj = {
							allowClear: false,
							cmd: 'Droplist_Supply',
							type: str,
							ListeningName: 'WmsEditChoice',
							refresherEnabled: false,
							serverSearch: {
								isPaging: false, //是否分页
								searchKey: 'SupplyName',
								showText: 'SupplyName', //查询结果显示的字段
								ChoiceDataKey: 'FSupplyID',
								ChoiceDataData: vm.form.FSupplyID
							},
							param: {
								SupplyName: ''
							}
						}
					}

					if (str == '产品批次_库位') {
						let productBoxID = $('.rowFBatchNoContainer #' + new_selectFname).parents(".productBox").attr(
							'id').replace('productBox', '');
						console.log(productBoxID);
						let searchProductID = $('.rowFBatchNoContainer #ProductID' + productBoxID).text();
						let searchFBatchNo = $('.rowFBatchNoContainer #FBatchNo' + productBoxID).text();

						console.log(JSON.stringify(searchProductID));
						console.log(JSON.stringify(searchFBatchNo));
						vm.baseScreenObj = {
							allowClear: false,
							cmd: 'Get_Storage_CPPCM',
							type: str,
							ListeningName: 'WmsEditChoice',
							refresherEnabled: false,
							serverSearch: {
								isPaging: false, //是否分页
								searchKey: 'FStorageCode', //搜索关键词，应包含在param中
								showText: 'FStorageCode', //查询结果显示的字段
								ChoiceDataKey: 'FStorageID',
								ChoiceDataData: $(".rowFBatchNoContainer #FStorageID" + productBoxID).text(),
								subText: [{
									label: '仓库名称',
									labelKey: 'FWarehouseName'
								}, {
									label: '可出库数量',
									labelKey: 'KCKQTY'
								}]
							},
							param: {
								FStorageCode: '',
								ProductID: searchProductID,
								FBatchNo: searchFBatchNo
							}
						};
					}

					this.sendMessage('baseScreen', vm.baseScreenObj);
				},

				sendMessage(action, data) {
					uni.postMessage({
						data: {
							action: action,
							data: data
						}
					})
				},

				onClickLeft() {
					uni.navigateBack();
					// 通知更新webview首页
					// uni.postMessage({
					// 	data: {
					// 		eventName: 'refreshList'
					// 	}
					// })
				}
			}
		})
	</script>
</html>